*cd "/Users/sanchariroy/Google Drive/Sanchari_F/DBW/data/prepared_data/"
cd "/Users/bsog0079/Dropbox/DBW/agencytrainingpaper/ReSTAT_revisions/prepared_data"
*cd "/Users/sr432/Google Drive/Sanchari_F/DBW/data/prepared_data_dropbox/"

use baseline_endline_data, clear

set more off

/*** This do file contains the code for the following Tables:
Main Tables: 1,2,3 and 6(Column 1 only)
Appendix Tables: A1, A2, A3, A4, A5, A6, A9, A10, A18, A19, A20 (column 1)
***/


********************************************************************************
***ATTRITION CHECKS*************************************************************
********************************************************************************

/**Table A1**/

bysort individ: egen count1=count(areacode)
ta count1 post, mi

gen surveyed_base_end=0
replace surveyed_base_end=1 if count1==2

ta surveyed_ post, mi

eststo clear

eststo: reg surveyed_ treat areadum1-areadum2 if post==0, cl(hhid)

eststo: reg surveyed_ treat age edu muslim babu_bline contrdum1_bline contrdum3_bline memdurb_bline ushac_bline logmthinc_bline areadum1-areadum2 if post==0, cl(hhid)

esttab using appendtables.rtf, replace se title(Appendix Table A1: Attrition Checks) cells(b(star fmt(2)) se(par fmt(2))) keep(treat age edu muslim babu_bline contrdum1_bline contrdum3_bline memdurb_bline ushac_bline logmthinc_bline) order(treat age edu muslim babu_bline contrdum1_bline contrdum3_bline memdurb_bline ushac_bline logmthinc_bline) indicate("Area fixed effects = areadum*") label starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2_a N, fmt(2 0) label("Adj. R-sq" "N"))


********************************************************************************
***RANDOMIZATION BALANCE CHECKS*************************************************
********************************************************************************


/**Table 1**/

eststo clear

	sort treat
	by treat: eststo: estpost summarize age muslim scst edu babu yrsinprof contrdum1-contrdum3 actratewc actratewoc custno_tot mthinc condom memdurb ushac if post==0	

	estpost ttest age muslim scst edu babu yrsinprof contrdum1-contrdum3 actratewc actratewoc custno_tot mthinc condom memdurb ushac if post==0, by(treat)
	matrix diff = e(b)
	eret2 matrix mean diff
	matrix se = e(se)
	eret2 matrix sd se
	eststo
	
	esttab using maintables.rtf, replace nonumber title(Table 1: Summary Statistics - Individual Characteristics  at Baseline) star cells("mean(fmt(2))" "sd(par fmt(2))") starlevels(* 0.10 ** 0.05 *** 0.01) mtitles("Control" "Treatment" "Difference") legend label nonotes

	* The standard errors in the table generated above need to be manually replaced by clustered standard errors from the following regressions:

	foreach var in age muslim scst edu babu yrsinprof contrdum1 contrdum2 contrdum3 actratewc actratewoc custno_tot mthinc condom memdurb ushac {
	reg `var' treat if post==0, cl(hhid)
}


	
/**Table 2**/

eststo clear

	sort treat
	by treat: eststo: estpost summarize resolve z_resolve decision z_decision happydum aspir sworth comf z_comf ashamed hlthchk if post==0
*using decision making raw score	
	estpost ttest resolve z_resolve decision z_decision happydum aspir sworth comf z_comf ashamed hlthchk if post==0, by(treat)
	matrix diff = e(b)
	eret2 matrix mean diff
	matrix se = e(se)
	eret2 matrix sd se
	eststo
	
	esttab using maintables.rtf, append nonumber title(Table 2: Summary Statistics - Means of Key Outcomes at Baseline) order(ashamed sworth resolve z_resolve comf z_comf happydum aspir decision z_decision hlthchk) star cells("mean(fmt(2))" "sd(par fmt(2))") starlevels(* 0.10 ** 0.05 *** 0.01) mtitles("Control" "Treatment" "Difference") legend label 

	* The standard errors in the table generated above need to be manually replaced by clustered standard errors from the following regressions:

	foreach var in resolve z_resolve decision z_decision happydum aspir sworth comf z_comf ashamed hlthchk {
	reg `var' treat if post==0, cl(hhid)
}


/**Table A9**/

*without bowbazar, for medium term results

eststo clear

	sort treat
	by treat: eststo: estpost summarize age muslim scst edu babu yrsinprof contrdum1-contrdum3 actratewc actratewoc custno_tot mthinc condom memdurb ushac if post==0&areacode~=2
	
	estpost ttest age muslim scst edu babu yrsinprof contrdum1-contrdum3 actratewc actratewoc custno_tot mthinc condom memdurb ushac if post==0&areacode~=2, by(treat)
	matrix diff = e(b)
	eret2 matrix mean diff
	matrix se = e(se)
	eret2 matrix sd se
	eststo
	
 	esttab using appendtables.rtf, append nonumber title(Appendix Table A9: Summary Statistics - Individual Characteristics  at Baseline, excluding Bowbazar) star cells("mean(fmt(2))" "sd(par fmt(2))") starlevels(* 0.10 ** 0.05 *** 0.01) mtitles("Control" "Treatment" "Difference") legend label 

	* The standard errors in the table generated above need to be manually replaced by clustered standard errors from the following regressions:

	foreach var in age muslim scst edu babu yrsinprof contrdum1 contrdum2 contrdum3 actratewc actratewoc custno_tot mthinc condom memdurb ushac {
	reg `var' treat if post==0&areacode~=2, cl(hhid)
}


/**Table A10**/

eststo clear

	sort treat
	by treat: eststo: estpost summarize resolve z_resolve decision z_decision happydum aspir sworth comf z_comf ashamed hlthchk if post==0&areacode~=2
	
	estpost ttest resolve z_resolve decision z_decision happydum aspir sworth comf z_comf ashamed hlthchk if post==0&areacode~=2, by(treat)
	matrix diff = e(b)
	eret2 matrix mean diff
	matrix se = e(se)
	eret2 matrix sd se
	eststo
	
	esttab using appendtables.rtf, append nonumber title(Appendix Table A10: Summary Statistics - Means of Key Outcomes at Baseline, excluding Bowbazar) order(ashamed sworth resolve z_resolve comf z_comf happydum aspir decision z_decision hlthchk) star cells("mean(fmt(2))" "sd(par fmt(2))") starlevels(* 0.10 ** 0.05 *** 0.01) mtitles("Control" "Treatment" "Difference") legend label 

	* The standard errors in the table generated above need to be manually replaced by clustered standard errors from the following regressions:

	foreach var in resolve z_resolve decision z_decision happydum aspir sworth comf z_comf ashamed hlthchk {
	reg `var' treat if post==0&areacode~=2, cl(hhid)
}

********************************************************************************
***REGRESSIONS: PSYCHOLOGICAL AND SELF-REPORTED HEALTH OUTCOMES*****************
********************************************************************************

/**Table 3**/

eststo clear

*Col 1
eststo reg1: reg ashamed treat ashamed_bline areadum1-areadum2 if post==1, cl(hhid)
ritest treat _b[treat], reps(1000) seed(125): `e(cmdline)'
matrix pvalues=r(p)
mat colnames pvalues = treat
est restore reg1

estadd matrix pvalues = pvalues

*Col 2
eststo reg2: reg sworth treat sworth_bline areadum1-areadum2 if post==1, cl(hhid)
ritest treat _b[treat], reps(1000) seed(125): `e(cmdline)'
matrix pvalues=r(p)
mat colnames pvalues = treat
est restore reg2 

estadd matrix pvalues = pvalues

*Col 3
eststo reg3: reg z_resolve treat z_resolve_bline areadum1-areadum2 if post==1, cl(hhid)
ritest treat _b[treat], reps(1000) seed(125): `e(cmdline)'
matrix pvalues=r(p)
mat colnames pvalues = treat
est restore reg3

estadd matrix pvalues = pvalues

*Col 4
eststo reg4: reg z_comf treat z_comf_bline areadum1-areadum2 if post==1, cl(hhid)
ritest treat _b[treat], reps(1000) seed(125): `e(cmdline)'
matrix pvalues=r(p)
mat colnames pvalues = treat
est restore reg4

estadd matrix pvalues = pvalues

*Col 6
eststo reg6: reg happydum treat happydum_bline areadum1-areadum2 if post==1, cl(hhid)
ritest treat _b[treat], reps(1000) seed(125): `e(cmdline)'
matrix pvalues=r(p)
mat colnames pvalues = treat
est restore reg6

estadd matrix pvalues = pvalues

*Col 7
eststo reg7: reg aspir treat aspir_bline areadum1-areadum2 if post==1, cl(hhid)
ritest treat _b[treat], reps(1000) seed(125): `e(cmdline)'
matrix pvalues=r(p)
mat colnames pvalues = treat
est restore reg7

estadd matrix pvalues = pvalues

*Col 8
eststo reg8: reg z_decision treat z_decision_bline areadum1-areadum2 if post==1, cl(hhid)
ritest treat _b[treat], reps(1000) seed(125): `e(cmdline)'
matrix pvalues=r(p)
mat colnames pvalues = treat
est restore reg8

estadd matrix pvalues = pvalues

esttab using maintables.rtf, append se title(Table 3: Program Impact on Proxies of Self-Image and Other Psychological Variables, ANCOVA) cells(b(star fmt(2)) se(par fmt(2)) pvalues(par([ ]))) keep(treat ashamed_bline sworth_bline z_resolve_bline z_comf_bline happydum_bline aspir_bline z_decision_bline) order(treat ashamed_bline sworth_bline z_resolve_bline z_comf_bline happydum_bline aspir_bline z_decision_bline) indicate("Area fixed effects = areadum*") label starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2_a N, fmt(2 0) label("Adj. R-sq" "N"))


/**Table A2**/

eststo clear

*Col 1
eststo reg1: reg ashamed treat ashamed_bline areadum1-areadum2 $controls if post==1, cl(hhid)
ritest treat _b[treat], reps(1000) seed(125): `e(cmdline)'
matrix pvalues=r(p)
mat colnames pvalues = treat
est restore reg1

estadd matrix pvalues = pvalues

*Col 2
eststo reg2: reg sworth treat sworth_bline areadum1-areadum2 $controls if post==1, cl(hhid)
ritest treat _b[treat], reps(1000) seed(125): `e(cmdline)'
matrix pvalues=r(p)
mat colnames pvalues = treat
est restore reg2 

estadd matrix pvalues = pvalues

*Col 3
eststo reg3: reg z_resolve treat z_resolve_bline areadum1-areadum2 $controls if post==1, cl(hhid)
ritest treat _b[treat], reps(1000) seed(125): `e(cmdline)'
matrix pvalues=r(p)
mat colnames pvalues = treat
est restore reg3

estadd matrix pvalues = pvalues

*Col 4
eststo reg4: reg z_comf treat z_comf_bline areadum1-areadum2 $controls if post==1, cl(hhid)
ritest treat _b[treat], reps(1000) seed(125): `e(cmdline)'
matrix pvalues=r(p)
mat colnames pvalues = treat
est restore reg4

estadd matrix pvalues = pvalues

*Col 6
eststo reg6: reg happydum treat happydum_bline areadum1-areadum2 $controls if post==1, cl(hhid)
ritest treat _b[treat], reps(1000) seed(125): `e(cmdline)'
matrix pvalues=r(p)
mat colnames pvalues = treat
est restore reg6

estadd matrix pvalues = pvalues

*Col 7
eststo reg7: reg aspir treat aspir_bline areadum1-areadum2 $controls if post==1, cl(hhid)
ritest treat _b[treat], reps(1000) seed(125): `e(cmdline)'
matrix pvalues=r(p)
mat colnames pvalues = treat
est restore reg7

estadd matrix pvalues = pvalues

*Col 8
eststo reg8: reg z_decision treat z_decision_bline areadum1-areadum2 $controls if post==1, cl(hhid)
ritest treat _b[treat], reps(1000) seed(125): `e(cmdline)'
matrix pvalues=r(p)
mat colnames pvalues = treat
est restore reg8

estadd matrix pvalues = pvalues

esttab using appendtables.rtf, append se title(Appendix Table A2: Program Impact on Proxies of Self-Image and Other Psychological Variables, ANCOVA with Baseline Controls) cells(b(star fmt(2)) se(par fmt(2)) pvalues(par([ ]))) keep(treat ashamed_bline sworth_bline z_resolve_bline z_comf_bline happydum_bline aspir_bline z_decision_bline) order(treat ashamed_bline sworth_bline z_resolve_bline z_comf_bline happydum_bline aspir_bline z_decision_bline) indicate("Area fixed effects = areadum*") label starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2_a N, fmt(2 0) label("Adj. R-sq" "N"))


/**Table A3**/

eststo clear

eststo: reg ashamed treat areadum1-areadum2 if post==1, cl(hhid)
eststo: reg sworth treat areadum1-areadum2 if post==1, cl(hhid)
eststo: reg z_resolve treat areadum1-areadum2 if post==1, cl(hhid)
eststo: reg z_comf treat areadum1-areadum2 if post==1, cl(hhid)
eststo: reg happydum treat areadum1-areadum2 if post==1, cl(hhid)
eststo: reg aspir treat areadum1-areadum2 if post==1, cl(hhid)
eststo: reg z_decision treat areadum1-areadum2 if post==1, cl(hhid)

esttab using appendtables.rtf, append se title(Appendix Table A3: Program Impact on Proxies of Self-Image and Other Psychological Variables, Endline) cells(b(star fmt(2)) se(par fmt(2)) pvalues(par([ ]))) keep(treat) order(treat) indicate("Area fixed effects = areadum*") label starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2_a N, fmt(2 0) label("Adj. R-sq" "N"))


/**Table A4**/

eststo clear

eststo: reg ashamed treat areadum1-areadum2 $controls if post==1, cl(hhid)
eststo: reg sworth treat areadum1-areadum2 $controls if post==1, cl(hhid)
eststo: reg z_resolve treat areadum1-areadum2 $controls if post==1, cl(hhid)
eststo: reg z_comf treat areadum1-areadum2 $controls if post==1, cl(hhid)
eststo: reg happydum treat areadum1-areadum2 $controls if post==1, cl(hhid)
eststo: reg aspir treat areadum1-areadum2 $controls if post==1, cl(hhid)
eststo: reg z_decision treat areadum1-areadum2 $controls if post==1, cl(hhid)

esttab using appendtables.rtf, append se title(Appendix Table A4: Program Impact on Proxies of Self-Image and Other Psychological Variables, Endline with Baseline Controls) cells(b(star fmt(2)) se(par fmt(2)) pvalues(par([ ]))) keep(treat) order(treat) indicate("Area fixed effects = areadum*") label starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2_a N, fmt(2 0) label("Adj. R-sq" "N"))


/**Table A5**/

eststo clear

eststo: reg ashamed treat post treatpost areadum1-areadum2, cl(hhid)
eststo: reg sworth treat post treatpost areadum1-areadum2, cl(hhid)
eststo: reg z_resolve treat post treatpost areadum1-areadum2, cl(hhid)
eststo: reg z_comf treat post treatpost areadum1-areadum2, cl(hhid)
eststo: reg happydum treat post treatpost areadum1-areadum2, cl(hhid)
eststo: reg aspir treat post treatpost areadum1-areadum2, cl(hhid)
eststo: reg z_decision treat post treatpost areadum1-areadum2, cl(hhid)

esttab using appendtables.rtf, append se title(Appendix Table A5: Program Impact on Proxies of Self-Image and Other Psychological Variables, Difference-in-differences) cells(b(star fmt(2)) se(par fmt(2)) pvalues(par([ ]))) keep(treat post treatpost) order(treat post treatpost) indicate("Area fixed effects = areadum*") label starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2_a N, fmt(2 0) label("Adj. R-sq" "N"))


/**Table A6**/

eststo clear

eststo: reg ashamed treat post treatpost $controls areadum1-areadum2, cl(hhid)
eststo: reg sworth treat post treatpost $controls areadum1-areadum2, cl(hhid)
eststo: reg z_resolve treat post treatpost $controls areadum1-areadum2, cl(hhid)
eststo: reg z_comf treat post treatpost $controls areadum1-areadum2, cl(hhid)
eststo: reg happydum treat post treatpost $controls areadum1-areadum2, cl(hhid)
eststo: reg aspir treat post treatpost $controls areadum1-areadum2, cl(hhid)
eststo: reg z_decision treat post treatpost $controls areadum1-areadum2, cl(hhid)

esttab using appendtables.rtf, append se title(Appendix Table A6: Program Impact on Proxies of Self-Image and Other Psychological Variables, Difference-in-differences with Baseline Controls) cells(b(star fmt(2)) se(par fmt(2)) pvalues(par([ ]))) keep(treat post treatpost) order(treat post treatpost) indicate("Area fixed effects = areadum*") label starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2_a N, fmt(2 0) label("Adj. R-sq" "N"))


/**Table 6**/

eststo clear

*Col 1
eststo reg1: reg hlthchk treat hlthchk_bline areadum1-areadum2 if post==1, cl(hhid)
ritest treat _b[treat], reps(1000) seed(125): `e(cmdline)'
matrix pvalues=r(p)
mat colnames pvalues = treat
est restore reg1

estadd matrix pvalues = pvalues

esttab using maintables.rtf, append se title(Table 6: Program Impact on Health-Seeking Behaviour, ANCOVA) cells(b(star fmt(2)) se(par fmt(2)) pvalues(par([ ]))) keep(treat hlthchk_bline) order(treat hlthchk_bline) indicate("Area fixed effects = areadum*") label starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2_a N, fmt(2 0) label("Adj. R-sq" "N"))


/**Appendix Table A18**/

eststo clear

*Col 1
eststo reg1: reg hlthchk treat areadum1-areadum2 if post==1, cl(hhid)

*Col 4
eststo reg2: reg hlthchk treat post treatpost areadum1-areadum2, cl(hhid)

esttab using appendtables.rtf, append se title(Appendix Table A18: Program Impact on Health-Seeking Behaviour, Endline and Difference-in-differences) cells(b(star fmt(2)) se(par fmt(2)) pvalues(par([ ]))) keep(treat post treatpost) order(treat post treatpost) indicate("Area fixed effects = areadum*") label starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2_a N, fmt(2 0) label("Adj. R-sq" "N"))


/**Appendix Table A19**/

eststo clear

eststo: reg logmthinc treat areadum1-areadum2 if post==1, cl(hhid)
eststo: reg logmthinc treat post treatpost areadum1-areadum2, cl(hhid)

eststo: reg custno_yst treat areadum1-areadum2 if post==1, cl(hhid)
eststo: reg custno_yst treat post treatpost areadum1-areadum2, cl(hhid)

esttab using appendtables.rtf, append se title(Appendix Table A19: Program Impact on Income and No. of Clients) cells(b(star fmt(2)) se(par fmt(2))) keep(treat post treatpost) order(treat post treatpost) indicate("Area fixed effects = areadum*") label starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2_a N, fmt(2 0) label("Adj. R-sq" "N"))


/**Appendix Table A20**/

eststo clear

sureg (ashamed sworth z_resolve z_comf happydum aspir z_decision hlthchk=treat areadum1 areadum2) if post==1, corr

*joint test of significance of the treat variable
test treat
